<?php
/**
 * 注：此模板为自动生成模板，需要根据实际情况调整修改
 * 此模板对 无主键/单一主键 表的支持较好，联合主键表在下一版本开发
 */
namespace Data;

use Utils\MyException;

class Consumer {

    //数组
    private $array;


    public function __construct ($array){

        $this->array = $array;

        self::setDefault();

    }

    public function getArray() {
        return $this->array;
    }

    public function updateWithArray($array) {
        foreach($array as $key=>$value)
        {
            if(array_key_exists($key,$this->array))
            {
                $this->array = array_merge($this->array,array($key=>$value));
            }
        }
    }



    private function setDefault(){

        if(count($this->array)==0){
            self::setCONSUMER_ID("null");
            self::setWX_ID("");
            self::setZFB_ID("");
            self::setCONSUMER_NAME("");
            self::setPHONE_NUMBER("0");
            self::setIMG_URL("");
            self::setLOGIN_TYPE("0");
            self::setCREATED_ON("");
            self::setCREATED_BY("0");
            self::setUPDATED_ON("");
            self::setUPDATED_BY("0");

        }
    }






    public function setCONSUMER_ID($value) {
        $this->array = array_merge ($this->array,array(
            'CONSUMER_ID' => $value));
    }
    public function getCONSUMER_ID(){

        return $this->array ['CONSUMER_ID'];
    }


    public function setWX_ID($value) {
        $this->array = array_merge ($this->array,array(
            'WX_ID' => $value));
    }
    public function getWX_ID(){

        return $this->array ['WX_ID'];
    }


    public function setZFB_ID($value) {
        $this->array = array_merge ($this->array,array(
            'ZFB_ID' => $value));
    }
    public function getZFB_ID(){

        return $this->array ['ZFB_ID'];
    }


    public function setCONSUMER_NAME($value) {
        $this->array = array_merge ($this->array,array(
            'CONSUMER_NAME' => $value));
    }
    public function getCONSUMER_NAME(){

        return $this->array ['CONSUMER_NAME'];
    }


    public function setPHONE_NUMBER($value) {
        $this->array = array_merge ($this->array,array(
            'PHONE_NUMBER' => $value));
    }
    public function getPHONE_NUMBER(){

        return $this->array ['PHONE_NUMBER'];
    }


    public function setIMG_URL($value) {
        $this->array = array_merge ($this->array,array(
            'IMG_URL' => $value));
    }
    public function getIMG_URL(){

        return $this->array ['IMG_URL'];
    }


    public function setLOGIN_TYPE($value) {
        $this->array = array_merge ($this->array,array(
            'LOGIN_TYPE' => $value));
    }
    public function getLOGIN_TYPE(){

        return $this->array ['LOGIN_TYPE'];
    }


    public function setCREATED_ON($value) {
        $this->array = array_merge ($this->array,array(
            'CREATED_ON' => $value));
    }
    public function getCREATED_ON(){

        return $this->array ['CREATED_ON'];
    }


    public function setCREATED_BY($value) {
        $this->array = array_merge ($this->array,array(
            'CREATED_BY' => $value));
    }
    public function getCREATED_BY(){

        return $this->array ['CREATED_BY'];
    }


    public function setUPDATED_ON($value) {
        $this->array = array_merge ($this->array,array(
            'UPDATED_ON' => $value));
    }
    public function getUPDATED_ON(){

        return $this->array ['UPDATED_ON'];
    }


    public function setUPDATED_BY($value) {
        $this->array = array_merge ($this->array,array(
            'UPDATED_BY' => $value));
    }
    public function getUPDATED_BY(){

        return $this->array ['UPDATED_BY'];
    }


    public function toInsertCSV() {
        $str="";

        // CONSUMER_ID
        $str .= self::getCONSUMER_ID().",";
        // WX_ID
        $str .= "'". self::getWX_ID()."',";
        // ZFB_ID
        $str .= "'". self::getZFB_ID()."',";
        // CONSUMER_NAME
        $str .= "'". self::getCONSUMER_NAME()."',";
        // PHONE_NUMBER
        $str .= "'". self::getPHONE_NUMBER()."',";
        // IMG_URL
        $str .= "'". self::getIMG_URL()."',";
        // LOGIN_TYPE
        $str .= "'". self::getLOGIN_TYPE()."',";
        // CREATED_ON
        $str .= "now()" . ",";

        // CREATED_BY
        $str .= "'". self::getCREATED_BY()."',";
        // UPDATED_ON
        $str .= "now()" . ",";

        // UPDATED_BY
        $str .= "'". self::getUPDATED_BY()."'";
        return $str;
    }



    public function toUpdateSet() {
        $str="";

        // WX_ID
        $str.= '`WX_ID` = "' . self::getWX_ID() . '",';

        // ZFB_ID
        $str.= '`ZFB_ID` = "' . self::getZFB_ID() . '",';

        // CONSUMER_NAME
        $str.= '`CONSUMER_NAME` = "' . self::getCONSUMER_NAME() . '",';

        // PHONE_NUMBER
        $str.= '`PHONE_NUMBER` = "' . self::getPHONE_NUMBER() . '",';

        // IMG_URL
        $str.= '`IMG_URL` = "' . self::getIMG_URL() . '",';

        // LOGIN_TYPE
        $str.= '`LOGIN_TYPE` = "' . self::getLOGIN_TYPE() . '",';

        // CREATED_ON
        $str.= '`CREATED_ON` = "' . self::getCREATED_ON() . '",';

        // CREATED_BY
        $str.= '`CREATED_BY` = "' . self::getCREATED_BY() . '",';

        // UPDATED_ON
        $str .= "UPDATED_ON = now()," ;

        // UPDATED_BY
        $str.= '`UPDATED_BY` = "' . self::getUPDATED_BY(). '"';
        return $str;
    }



    public function toUpdateWhere(){
        $str = "";
        $str .= "`CONSUMER_ID` = '" . self::getCONSUMER_ID()."'";
        return $str;
    }

}

